package at.fhj.antesk.steamvaluecalc.view;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import at.fhj.antesk.steamvaluecalc.resources.Configs;

public class AboutWindow extends JFrame {

	private static final long serialVersionUID = -7413312009538260781L;
	private JPanel contentPane;
	private Map<String, String> configsMap = Configs.getInstance().getConfigsMap();
	
	public AboutWindow() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(AboutWindow.class.getResource("/resources/spicon.gif")));
		setTitle(configsMap.get("aboutwindow.title"));
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		setLocationRelativeTo(null);
		contentPane = new JPanel();
		contentPane.setForeground(Color.WHITE);
		contentPane.setBackground(Color.DARK_GRAY);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblHeading = new JLabel(configsMap.get("aboutwindow.label.heading"));
		lblHeading.setHorizontalAlignment(SwingConstants.CENTER);
		lblHeading.setFont(new Font("Verdana", Font.PLAIN, 18));
		lblHeading.setForeground(Color.WHITE);
		lblHeading.setBounds(10, 11, 424, 35);
		contentPane.add(lblHeading);
		
		// configsMap.get("aboutwindow.label.description"
		JLabel lblDescription = new JLabel(configsMap.get("aboutwindow.label.description"));
		lblDescription.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblDescription.setForeground(Color.WHITE);
		lblDescription.setBounds(10, 57, 424, 23);
		contentPane.add(lblDescription);
		
		JButton btnClose = new JButton(configsMap.get("aboutwindow.button.close"));
		btnClose.setBackground(Color.LIGHT_GRAY);
		btnClose.setFont(new Font("Tahoma", Font.PLAIN, 11));
		btnClose.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				AboutWindow.this.dispose();
			}
		});
		btnClose.setBounds(180, 238, 89, 23);
		contentPane.add(btnClose);
		
		JPanel dataPanel = new JPanel();
		dataPanel.setBackground(Color.DARK_GRAY);
		dataPanel.setBounds(10, 92, 424, 69);
		contentPane.add(dataPanel);
		dataPanel.setLayout(null);
		
		JLabel lblVersion = new JLabel(configsMap.get("aboutwindow.label.version.header"));
		lblVersion.setBounds(0, 0, 39, 14);
		dataPanel.add(lblVersion);
		lblVersion.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblVersion.setForeground(Color.WHITE);
		
		JLabel lblVersionnum = new JLabel(configsMap.get("aboutwindow.label.version"));
		lblVersionnum.setBounds(40, 0, 16, 14);
		dataPanel.add(lblVersionnum);
		lblVersionnum.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblVersionnum.setForeground(Color.WHITE);
		
		JLabel lblRelease = new JLabel(configsMap.get("aboutwindow.label.release.header"));
		lblRelease.setBounds(0, 15, 68, 14);
		dataPanel.add(lblRelease);
		lblRelease.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblRelease.setForeground(Color.WHITE);
		
		JLabel lblReleasedate = new JLabel(configsMap.get("aboutwindow.label.release"));
		lblReleasedate.setBounds(69, 15, 56, 14);
		dataPanel.add(lblReleasedate);
		lblReleasedate.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblReleasedate.setForeground(Color.WHITE);
		
		JLabel lblCopyright = new JLabel(configsMap.get("aboutwindow.label.copyright.header"));
		lblCopyright.setBounds(0, 30, 51, 14);
		dataPanel.add(lblCopyright);
		lblCopyright.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblCopyright.setForeground(Color.WHITE);
		
		JLabel lblCopyrightdata = new JLabel(configsMap.get("aboutwindow.label.copyright"));
		lblCopyrightdata.setBounds(52, 30, 125, 14);
		dataPanel.add(lblCopyrightdata);
		lblCopyrightdata.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblCopyrightdata.setForeground(Color.WHITE);
		
		JLabel lblWebsite = new JLabel(configsMap.get("aboutwindow.label.website.header"));
		lblWebsite.setBounds(0, 45, 43, 14);
		dataPanel.add(lblWebsite);
		lblWebsite.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblWebsite.setForeground(Color.WHITE);
		
		JLabel lblWebsiteurl = new JLabel(configsMap.get("aboutwindow.label.website"));
		lblWebsiteurl.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent arg0) {
				try {
					Desktop.getDesktop().browse(new URI(configsMap.get("aboutwindow.label.website").replace("<html>", "").replace("<u>", "").replace("</html>", "").replace("</u>", "")));
				} catch (IOException e) {
					e.printStackTrace();
				} catch (URISyntaxException e) {
					e.printStackTrace();
				}
			}
		});
		lblWebsiteurl.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		lblWebsiteurl.setBounds(45, 45, 295, 14);
		dataPanel.add(lblWebsiteurl);
		lblWebsiteurl.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblWebsiteurl.setForeground(Color.WHITE);
		
		JLabel lblDescription2 = new JLabel(configsMap.get("aboutwindow.label.description2"));
		lblDescription2.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblDescription2.setForeground(Color.WHITE);
		lblDescription2.setVerticalAlignment(SwingConstants.TOP);
		lblDescription2.setBounds(10, 173, 424, 54);
		contentPane.add(lblDescription2);
	}
}
